package com.yanqu.road.server.gameplayer.module.activity.goddess;

import com.yanqu.road.entity.activity.ActivityConfig;
import com.yanqu.road.entity.activity.ActivityInfo;
import com.yanqu.road.entity.activity.goddess.config.*;
import com.yanqu.road.entity.enums.eActivityConfigType;
import com.yanqu.road.utils.RandomHelper;
import com.yanqu.road.utils.string.StringUtils;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Random;

public class GoddessConfig {

    /**
     * 列数
     */
    public int COLUMN_NUM = 7;

    /**
     * 行数
     */
    public int ROW_NUM = 7;

    //积分道具id
    private int scoreItemId;

    //消耗一点体力获得积分
    private int energyScoreNum;

    //体力道具id（开天玉露）
    private int energyRecItemId;

    //五彩石背包最大数量
    private int bagMaxNumStone;

    //两仪石背包最大数量
    private int bagMaxNumLiangYi;

    //地图大小（横|竖）
    private List<Integer> mapSizeList;

    //基础点数随机参数（点数最小值；权重|下一区间点数最小值；权重|……）
    private String pointBaseRandom;

    //引导
    List<String> guideList = new ArrayList<>();

    private ActivityInfo activityInfo;

    public GoddessConfig(ActivityInfo activityInfo) {
        this.activityInfo = activityInfo;
    }

    public void init(Map<String, ActivityConfig> activityConfigMap){
        if(activityConfigMap.containsKey(eActivityConfigType.EXCHANGE_SCORE_ITEM_ID.getName())){
            this.scoreItemId = activityConfigMap.get(eActivityConfigType.EXCHANGE_SCORE_ITEM_ID.getName()).getIntValue();
        }

        if(activityConfigMap.containsKey(eActivityConfigType.FIXSKY_ENERGY_ITEM_ID.getName())){
            this.energyRecItemId = activityConfigMap.get(eActivityConfigType.FIXSKY_ENERGY_ITEM_ID.getName()).getIntValue();
        }

        if(activityConfigMap.containsKey(eActivityConfigType.FIXSKY_BAG_MAXNUM_STONE.getName())){
            this.bagMaxNumStone = activityConfigMap.get(eActivityConfigType.FIXSKY_BAG_MAXNUM_STONE.getName()).getIntValue();
        }

        if(activityConfigMap.containsKey(eActivityConfigType.FIXSKY_BAG_MAXNUM_LIANGYI.getName())){
            this.bagMaxNumLiangYi = activityConfigMap.get(eActivityConfigType.FIXSKY_BAG_MAXNUM_LIANGYI.getName()).getIntValue();
        }

        if(activityConfigMap.containsKey(eActivityConfigType.FIXSKY_ENERGY_SCORE_NUM.getName())){
            this.energyScoreNum = activityConfigMap.get(eActivityConfigType.FIXSKY_ENERGY_SCORE_NUM.getName()).getIntValue();
        }

        if(activityConfigMap.containsKey(eActivityConfigType.FIXSKY_POINT_BASE_RANDOM.getName())){
            this.pointBaseRandom = activityConfigMap.get(eActivityConfigType.FIXSKY_POINT_BASE_RANDOM.getName()).getValue();
        }

        if(activityConfigMap.containsKey(eActivityConfigType.FIXSKY_MAP_SIZE.getName())){
            this.mapSizeList = StringUtils.stringToIntegerList(activityConfigMap.get(eActivityConfigType.FIXSKY_MAP_SIZE.getName()).getValue(), "\\|");
            if(mapSizeList.size() == 2){
                COLUMN_NUM = mapSizeList.get(1);
                ROW_NUM = mapSizeList.get(0);
            }
        }

        if(activityConfigMap.containsKey(eActivityConfigType.FIXSKY_NEWGUIDE.getName())){
            this.guideList = StringUtils.stringToStringList(activityConfigMap.get(eActivityConfigType.FIXSKY_NEWGUIDE.getName()).getValue(), "\\|");
        }
    }

    public ActivityInfo getActivityInfo() {
        return activityInfo;
    }

    public GoddessEraInfo getGoddessEraInfo(int eraId){
        for (GoddessEraInfo eraInfo : eraInfoList) {
            if(eraId == eraInfo.getEraId()){
                return eraInfo;
            }
        }
        return null;
    }

    public GoddessMissionInfo getGoddessMissionInfo(int missionId){
        for (GoddessMissionInfo missionInfo : this.missionInfoList) {
            if(missionId == missionInfo.getMissionId()){
                return missionInfo;
            }
        }
        return null;
    }

    public GoddessRandomStoneInfo getGoddessRandomStoneInfo(int shapeId){
        for (GoddessRandomStoneInfo stoneInfo : shapeInfoList) {
            if(shapeId == stoneInfo.getShapeId()){
                return stoneInfo;
            }
        }
        return null;
    }

    public GoddessRandomStoneInfo getRandomStoneInfo(int colorStoneLv, Random random){
        GoddessRandomStoneInfo stoneInfo = getGoddessRandomStoneInfo(colorStoneLv);
        if(stoneInfo != null){
            List<String> paramList = StringUtils.stringToStringList(stoneInfo.getShape(), "\\|");
            List<Integer> valList = new ArrayList<>();
            List<Integer> weightList = new ArrayList<>();
            for (String str : paramList) {
                List<Integer> list = StringUtils.stringToIntegerList(str, ";");
                if(list.size() == 2){
                    valList.add(list.get(0));
                    weightList.add(list.get(1));
                }
            }
            int idx = RandomHelper.getRandomIndexByWeight(weightList, random);
            int shapeId = valList.get(idx);
            return getGoddessRandomStoneInfo(shapeId);
        }
        return null;
    }

    public GoddessLiangYiStoneInfo getGoddessLiangYiStoneInfo(int lv){
        for (GoddessLiangYiStoneInfo liangYiStoneInfo : liangYiStoneInfoList) {
            if(lv == liangYiStoneInfo.getLiangYiLv()){
                return liangYiStoneInfo;
            }
        }
        return null;
    }

    private List<GoddessEraInfo> eraInfoList;

    private List<GoddessLiangYiStoneInfo> liangYiStoneInfoList;

    private List<GoddessRandomStoneInfo> shapeInfoList;

    private List<GoddessPeopleInfo> peopleInfoList;

    private List<GoddessPeoBookInfo> bookInfoList;

    private List<GoddessMissionInfo> missionInfoList;

    public long getAuraGetCd() {
        return 0;
    }

    public int getAuraGetNum() {
        return 1;
    }

    public int getAuraMax() {
        return 0;
    }

    public int getEnergyRecItemId() {
        return energyRecItemId;
    }

    public void setEnergyRecItemId(int energyRecItemId) {
        this.energyRecItemId = energyRecItemId;
    }

    public List<GoddessEraInfo> getEraInfoList() {
        return eraInfoList;
    }

    public void setEraInfoList(List<GoddessEraInfo> eraInfoList) {
        this.eraInfoList = eraInfoList;
    }

    public List<GoddessLiangYiStoneInfo> getLiangYiStoneInfoList() {
        return liangYiStoneInfoList;
    }

    public void setLiangYiStoneInfoList(List<GoddessLiangYiStoneInfo> liangYiStoneInfoList) {
        this.liangYiStoneInfoList = liangYiStoneInfoList;
    }

    public int getScoreItemId() {
        return scoreItemId;
    }

    public void setScoreItemId(int scoreItemId) {
        this.scoreItemId = scoreItemId;
    }

    public int getBagMaxNumStone() {
        return bagMaxNumStone;
    }

    public void setBagMaxNumStone(int bagMaxNumStone) {
        this.bagMaxNumStone = bagMaxNumStone;
    }

    public int getBagMaxNumLiangYi() {
        return bagMaxNumLiangYi;
    }

    public void setBagMaxNumLiangYi(int bagMaxNumLiangYi) {
        this.bagMaxNumLiangYi = bagMaxNumLiangYi;
    }

    public List<Integer> getMapSizeList() {
        return mapSizeList;
    }

    public void setMapSizeList(List<Integer> mapSizeList) {
        this.mapSizeList = mapSizeList;
    }

    public void setActivityInfo(ActivityInfo activityInfo) {
        this.activityInfo = activityInfo;
    }

    public List<GoddessRandomStoneInfo> getShapeInfoList() {
        return shapeInfoList;
    }

    public void setShapeInfoList(List<GoddessRandomStoneInfo> shapeInfoList) {
        this.shapeInfoList = shapeInfoList;
    }

    public List<GoddessPeopleInfo> getPeopleInfoList() {
        return peopleInfoList;
    }

    public void setPeopleInfoList(List<GoddessPeopleInfo> peopleInfoList) {
        this.peopleInfoList = peopleInfoList;
    }

    public List<GoddessPeoBookInfo> getBookInfoList() {
        return bookInfoList;
    }

    public void setBookInfoList(List<GoddessPeoBookInfo> bookInfoList) {
        this.bookInfoList = bookInfoList;
    }

    public List<GoddessMissionInfo> getMissionInfoList() {
        return missionInfoList;
    }

    public void setMissionInfoList(List<GoddessMissionInfo> missionInfoList) {
        this.missionInfoList = missionInfoList;
    }

    public int getEnergyScoreNum() {
        return energyScoreNum;
    }

    public void setEnergyScoreNum(int energyScoreNum) {
        this.energyScoreNum = energyScoreNum;
    }

    public String getPointBaseRandom() {
        return pointBaseRandom;
    }

    public void setPointBaseRandom(String pointBaseRandom) {
        this.pointBaseRandom = pointBaseRandom;
    }

    public List<String> getGuideList() {
        return guideList;
    }
}
